/**
 * 作者: clz
 * 日期: 2025-05-09 08:50:58
 * 备注: 联盟远征模块信息
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUnionBossInfo;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UnionBossInfoModel extends BaseModel implements Model {
	public static final String LISTKEY = "";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // 联盟id
	protected int stageId; // 关卡id
	protected long initHp; // 初始血量
	protected long hp; // 剩余血量
	protected long chatTime; // 集结令发布时间

	public void reset() {
	}

	protected String getKey() {
		return "UnionBossInfo." + id;
	}

	protected String getListKey() {
		return null;
	}

	protected String getListItemKey() {
		return null;
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("union_boss_info"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	 * 根据入库类型更新
	 */
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	 * 实时入队列
	 */
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // 联盟id
		obj.put("stageId", stageId); // 关卡id
		obj.put("initHp", initHp); // 初始血量
		obj.put("hp", hp); // 剩余血量
		obj.put("chatTime", chatTime); // 集结令发布时间
		return obj;
	}

	public PBUnionBossInfo.Builder takeInitBuilder() {
		PBUnionBossInfo.Builder sb = PBUnionBossInfo.newBuilder();
		if (stageId != 0) {
			sb.setStageId(stageId);
		}
		if (initHp != 0) {
			sb.setInitHp(initHp);
		}
		if (hp != 0) {
			sb.setHp(hp);
		}
		if (chatTime != 0) {
			sb.setChatTime(chatTime);
		}
		return sb;
	}

	public PBUnionBossInfo.Builder takeBuilder() {
		if (updateObj == null || updateObj.isEmpty()) {
			return takeInitBuilder();
		}
		PBUnionBossInfo.Builder sb = PBUnionBossInfo.newBuilder();
		if (isFieldUpdate("stageId")) {
			sb.setStageId(stageId);
		}
		if (isFieldUpdate("initHp")) {
			sb.setInitHp(initHp);
		}
		if (isFieldUpdate("hp")) {
			sb.setHp(hp);
		}
		if (isFieldUpdate("chatTime")) {
			sb.setChatTime(chatTime);
		}
		return sb;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public int getStageId() {
		return stageId;
	}

	public void putStageId(int stageId) {
		if (this.stageId != stageId) {
			this.stageId = stageId;
			updateRedisHashField(getKey(), "stageId", this.stageId);
		}
	}

	public void addStageId(int value) {
		this.stageId += value;
		updateRedisHashField(getKey(), "stageId", this.stageId);
	}

	public long getInitHp() {
		return initHp;
	}

	public void putInitHp(long initHp) {
		if (this.initHp != initHp) {
			this.initHp = initHp;
			updateRedisHashField(getKey(), "initHp", this.initHp);
		}
	}

	public void addInitHp(long value) {
		this.initHp += value;
		updateRedisHashField(getKey(), "initHp", this.initHp);
	}

	public long getHp() {
		return hp;
	}

	public void putHp(long hp) {
		if (this.hp != hp) {
			this.hp = hp;
			updateRedisHashField(getKey(), "hp", this.hp);
		}
	}

	public void addHp(long value) {
		this.hp += value;
		updateRedisHashField(getKey(), "hp", this.hp);
	}

	public long getChatTime() {
		return chatTime;
	}

	public void putChatTime(long chatTime) {
		if (this.chatTime != chatTime) {
			this.chatTime = chatTime;
			updateRedisHashField(getKey(), "chatTime", this.chatTime);
		}
	}

	public void addChatTime(long value) {
		this.chatTime += value;
		updateRedisHashField(getKey(), "chatTime", this.chatTime);
	}

}